import requests
from lxml import etree
if __name__ == '__main__':
    url = 'https://jn.58.com/ershoufang/?PGTID=0d100000-0010-9adb-c6e8-dabb658d2c1d'
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54'
    }
    page_text=requests.get(url=url,headers=headers).text
    tree = etree.HTML(page_text)
    div_list = tree.xpath('//section[@class="list"][1]/div')
    fp = open('./58tongcheng.txt','w',encoding='utf-8')
    for div in div_list:
        title = div.xpath('./a/div[2]//h3/text()')[0]
        price = div.xpath('./a/div[2]//span[@class="property-price-total-num"]/text()')[0]
        print(title)
        fp.write(title+'---------------'+price+'wanyuan'+'\n')
